package com.teapos.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.teapos.enumtype.TradeTypeEnum;
import com.teapos.service.SummaryService;
import com.teapos.service.TradeService;
import com.teapos.util.Maps;
import com.teapos.util.ThreadLocalUtil;
import com.teapos.util.Tool;

@SuppressWarnings({"rawtypes", "unchecked"})
@RequestMapping("/summary")
@Controller
public class SummaryController extends BaseController {
	
	@Autowired
	private SummaryService summaryService;
	@Autowired
	private TradeService tradeService;
	
	@RequestMapping("/index")
	public String index(HttpServletRequest req, Map map) {
		List stores = tradeService.getUserStores(super.getUserId(req));
		map.put("stores", stores);
		map.put("tradeTypes", TradeTypeEnum.values());
		Map param = super.getParaMap(req);
		if(stores.size()==1) param.put("storeId", ((Map)stores.get(0)).get("store_id"));
		map.put("orders", summaryService.getSummary(param));
		map.put("sum", ThreadLocalUtil.get("sum"));
		map.put("sum2", ThreadLocalUtil.get("sum2"));
		int pageNo = Tool.initPageNo(req.getParameter("pageNo"));
		map.put("page", Maps.newHashMap("pageNo", pageNo, "total", summaryService.getCount(super.getParaMap(req)), "js", "turnpage"));
		map.put("query", super.getParaMap(req));
		return "summary/index";
	}

}
